#include "SceneManager.h"

SceneManager* SceneManager::_instance=NULL;

SceneManager* SceneManager::GetInstance()
{
	if(_instance==NULL)
	{
		_instance=new SceneManager();
	}

	return _instance; 
}


SceneManager::SceneManager()
{
	 //Chua bik lam gi... tham khao website
	/*_topStack=-1;*/
}


Scene* SceneManager::GetCurrentScene()
{
	if(_sceneList.size()>0)
	{
		list<Scene*>::iterator i;
		i=_sceneList.end();
		i--;

		return *i;
	}
	else
	{
		return NULL;
	}
}

void SceneManager::PushScene(Scene* newScene)
{
	if(GetCurrentScene()!=NULL)
		GetCurrentScene()->Pause();

	_sceneList.push_back(newScene);
}


void SceneManager::PopScene()
{
	GetCurrentScene()->Leave();

	_sceneList.pop_back();

	GetCurrentScene()->Resume();
}

void SceneManager::ClearSceneStack()
{

	int i=_sceneList.size();

	while(i>0)
	{
		PopScene();
		i--;
	}
}

void SceneManager::GoToFirst()
{
	int i=_sceneList.size()-1;

	while(i>0)
	{
		PopScene();
		i--;
	}
	
}

void SceneManager::Update(float DeltaTime)
{
	Scene *currentScene=GetCurrentScene();

	if(currentScene!=0)
		currentScene->Update(DeltaTime);
}

void SceneManager::Render()
{
	Scene *currentScene=GetCurrentScene();

	if(currentScene!=0)
		currentScene->Render();

}
